package com.uzai.console.service.ciku.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.taobao.api.internal.toplink.embedded.websocket.util.StringUtil;
import com.uzai.common.enums.MerConfigKeyEnum;
import com.uzai.common.enums.MerConfigTypeEnum;
import com.uzai.common.exception.BusinessException;
import com.uzai.common.result.ResponseCode;
import com.uzai.console.common.ResponseMsg;
import com.uzai.console.common.utils.DateUtil;
import com.uzai.console.common.utils.Tools;
import com.uzai.console.dto.ciku.*;
import com.uzai.console.entity.CikuKeywords;
import com.uzai.console.entity.MerBaseConfig;
import com.uzai.console.entity.CikuKeywordsReply;
import com.uzai.console.mapper.CikuKeywordsMapper;
import com.uzai.console.mapper.CikuKeywordsReplyMapper;
import com.uzai.console.mapper.MerBaseConfigMapper;
import com.uzai.console.service.ciku.CikuKeywordsReplyService;
import com.uzai.console.vo.ciku.CikuKeywordsInfoVo;
import com.uzai.console.vo.ciku.CikuKeywordsReplyInfoVo;
import com.uzai.console.vo.ciku.CikuReplyConfigVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liuqi
 * @date 2021年08月23日 20:25
 */
@Service
public class CikuKeywordsReplyServiceImpl implements CikuKeywordsReplyService {

    @Autowired
    private MerBaseConfigMapper merBaseConfigMapper;
    @Autowired
    private CikuKeywordsReplyMapper cikuKeywordsReplyMapper;
    @Autowired
    private CikuKeywordsMapper cikuKeywordsMapper;

    /**
     * 查询词库超级问答配置信息
     * @author liuqi
     * @date 2021/8/13 11:38
     * @return null
     */
    public CikuReplyConfigVo findCikuReplayConfig(Long merId){

       CikuReplyConfigVo cikuReplyConfigVo = new CikuReplyConfigVo();

        //查询允许私聊回复开关
        MerBaseConfig merBaseConfig_cikuPrivateChat = merBaseConfigMapper.selectByMerId(merId, MerConfigKeyEnum.CIKU_PRIVATE_CHAT_SWITCH.getValue());
        if(merBaseConfig_cikuPrivateChat != null ){
            cikuReplyConfigVo.setCikuPrivateChatSwitch(Integer.valueOf(merBaseConfig_cikuPrivateChat.getVal()));
        }

        //查询允许群里回复开关
        MerBaseConfig merBaseConfig_cikuGroupChat = merBaseConfigMapper.selectByMerId(merId, MerConfigKeyEnum.CIKU_GROUP_CHAT_SWITCH.getValue());
        if(merBaseConfig_cikuGroupChat != null ){
            cikuReplyConfigVo.setCikuGroupChatSwitch(Integer.valueOf(merBaseConfig_cikuGroupChat.getVal()));
        }

        return cikuReplyConfigVo;
    }

    /**
     * 修改超级问答配置详情
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param cikuReplyConfigDto
     * @return null
     */
    @Transactional
    public void updateCikuReplayConfig(CikuReplyConfigDto cikuReplyConfigDto){

        if(cikuReplyConfigDto.getCikuPrivateChatSwitch() == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入允许私聊配置");
        }

        if(cikuReplyConfigDto.getCikuGroupChatSwitch() == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入允许群聊配置");
        }

        Integer now = DateUtil.getNowTime();
        //修改私聊配置
        MerBaseConfig merBaseConfig_privateChat = merBaseConfigMapper.selectByMerId(cikuReplyConfigDto.getMerId(), MerConfigKeyEnum.CIKU_PRIVATE_CHAT_SWITCH.getValue());

        if (merBaseConfig_privateChat != null){
            merBaseConfig_privateChat.setVal(String.valueOf(cikuReplyConfigDto.getCikuPrivateChatSwitch()));
            merBaseConfig_privateChat.setUpdateTime(now);
            merBaseConfigMapper.update(merBaseConfig_privateChat);
        } else { //增加私聊配置
            merBaseConfig_privateChat = new MerBaseConfig();
            merBaseConfig_privateChat.setId(IdWorker.getId());
            merBaseConfig_privateChat.setMerId(cikuReplyConfigDto.getMerId());
            merBaseConfig_privateChat.setType(MerConfigTypeEnum.PRODUCTS.getValue());
            merBaseConfig_privateChat.setKey(MerConfigKeyEnum.CIKU_PRIVATE_CHAT_SWITCH.getValue());
            merBaseConfig_privateChat.setVal(String.valueOf(cikuReplyConfigDto.getCikuPrivateChatSwitch()));
            merBaseConfig_privateChat.setCreateTime(now);
            merBaseConfig_privateChat.setUpdateTime(now);
            merBaseConfigMapper.insert(merBaseConfig_privateChat);
        }

       //修改群聊配置
        MerBaseConfig merBaseConfig_groupChat = merBaseConfigMapper.selectByMerId(cikuReplyConfigDto.getMerId(), MerConfigKeyEnum.CIKU_GROUP_CHAT_SWITCH.getValue());

        if (merBaseConfig_groupChat != null){
            merBaseConfig_groupChat.setVal(String.valueOf(cikuReplyConfigDto.getCikuGroupChatSwitch()));
            merBaseConfig_groupChat.setUpdateTime(now);
            merBaseConfigMapper.update(merBaseConfig_groupChat);
        } else { //增加群聊配置
            merBaseConfig_groupChat = new MerBaseConfig();
            merBaseConfig_groupChat.setId(IdWorker.getId());
            merBaseConfig_groupChat.setMerId(cikuReplyConfigDto.getMerId());
            merBaseConfig_groupChat.setType(MerConfigTypeEnum.PRODUCTS.getValue());
            merBaseConfig_groupChat.setKey(MerConfigKeyEnum.CIKU_GROUP_CHAT_SWITCH.getValue());
            merBaseConfig_groupChat.setVal(String.valueOf(cikuReplyConfigDto.getCikuGroupChatSwitch()));
            merBaseConfig_groupChat.setCreateTime(now);
            merBaseConfig_groupChat.setUpdateTime(now);
            merBaseConfigMapper.insert(merBaseConfig_groupChat);
        }
    }

    /**
     * 查询超级问答回复语列表
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param cikuKeywordsReplyQuery
     * @return null
     */
    public Page<CikuKeywordsReplyInfoVo> findCikuKeywordsReplyList(CikuKeywordsReplyQuery cikuKeywordsReplyQuery){
        //新建返回到页面的LIST对象
        List<CikuKeywordsReplyInfoVo> cikuKeywordsReplyPageVoList = new ArrayList<>();

        //执行分页查询对象
        Page<CikuKeywordsReply> page = new Page<>();
        cikuKeywordsReplyQuery.convert(page);
        ArrayList<CikuKeywordsReply> cikuKeywordsReplyList =  cikuKeywordsReplyMapper.findByList(page, cikuKeywordsReplyQuery);
        if(cikuKeywordsReplyList != null && cikuKeywordsReplyList.size() > 0){
            for (CikuKeywordsReply cikuKeywordsReply : cikuKeywordsReplyList){
                CikuKeywordsReplyInfoVo cikuKeywordsReplyPageVo = new CikuKeywordsReplyInfoVo();
                BeanUtils.copyProperties(cikuKeywordsReply, cikuKeywordsReplyPageVo);

                String content  = cikuKeywordsReply.getContent();
                if(cikuKeywordsReply.getType() == 0){//常规回复
                    cikuKeywordsReplyPageVo.setReply(cikuKeywordsReply.getContent());
                }else if(cikuKeywordsReply.getType() == 1){//卡片回复
                    JSONObject contentObject = JSONObject.parseObject(content);
                    cikuKeywordsReplyPageVo.setCardtitle(contentObject.getString("cardtitle"));
                    cikuKeywordsReplyPageVo.setCardurl(contentObject.getString("cardurl"));
                    cikuKeywordsReplyPageVo.setCardicon(contentObject.getString("cardicon"));
                    cikuKeywordsReplyPageVo.setCarddesc(contentObject.getString("carddesc"));
                }else if(cikuKeywordsReply.getType() == 2){//小程序回复
                    JSONObject contentObject = JSONObject.parseObject(content);
                    cikuKeywordsReplyPageVo.setMiniProName(contentObject.getString("miniProName"));
                    cikuKeywordsReplyPageVo.setMiniProTitle(contentObject.getString("miniProTitle"));
                    cikuKeywordsReplyPageVo.setMiniProUrl(contentObject.getString("miniProUrl"));
                    cikuKeywordsReplyPageVo.setMiniProDesc(contentObject.getString("miniProDesc"));
                    cikuKeywordsReplyPageVo.setMiniImgPwdStr(contentObject.getString("miniImgPwdStr"));
                    cikuKeywordsReplyPageVo.setMiniImgStr(contentObject.getString("miniImgStr"));
                    cikuKeywordsReplyPageVo.setMiniProAppId(contentObject.getString("miniProAppId"));
                    cikuKeywordsReplyPageVo.setMiniProGhId(contentObject.getString("miniProGhId"));
                }else if(cikuKeywordsReply.getType() == 3){//微信好友名片
                    cikuKeywordsReplyPageVo.setWxid(cikuKeywordsReply.getContent());
                }

                //关键字列表
                CikuKeywordsQuery cikuKeywordsQuery = new CikuKeywordsQuery();
                cikuKeywordsQuery.setMerId(cikuKeywordsReply.getMerId());
                cikuKeywordsQuery.setReplyId(cikuKeywordsReply.getId());
                List<CikuKeywords> cikuKeywordsList = cikuKeywordsMapper.findByList(cikuKeywordsQuery);
                if(cikuKeywordsList != null && cikuKeywordsList.size() > 0){
                    List<CikuKeywordsInfoVo> cikuKeywordsInfoVoList = new ArrayList<>();
                    List<String> keywordList = new ArrayList<>();
                    for (CikuKeywords cikuKeywords : cikuKeywordsList){
                        CikuKeywordsInfoVo cikuKeywordsInfoVo = new CikuKeywordsInfoVo();
                        BeanUtils.copyProperties(cikuKeywords, cikuKeywordsInfoVo);
                        cikuKeywordsInfoVoList.add(cikuKeywordsInfoVo);
                        keywordList.add(cikuKeywords.getKeyword());
                    }
                    cikuKeywordsReplyPageVo.setCikuKeywordsInfoDtoList(cikuKeywordsInfoVoList);
                    cikuKeywordsReplyPageVo.setKeywordList(keywordList);
                }
                cikuKeywordsReplyPageVoList.add(cikuKeywordsReplyPageVo);
            }
        }
        //返回到页面分页对象
        Page<CikuKeywordsReplyInfoVo> pageVo = new Page<>();
        BeanUtils.copyProperties(page, pageVo);
        pageVo.setRecords(cikuKeywordsReplyPageVoList);
        //将分页信息复制到返回到页面的分页MO当中
        return pageVo;
    }

    /**
     * 添加超级问答回复语
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param cikuKeywordsReplyInfoDto
     * @return null
     */
    @Transactional
    public void addCikuKeywordsReply(CikuKeywordsReplyInfoDto cikuKeywordsReplyInfoDto){

        if(cikuKeywordsReplyInfoDto.getType() == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入回复语类型");
        }

        if(cikuKeywordsReplyInfoDto.getCikuKeywordsInfoDtoList() == null || cikuKeywordsReplyInfoDto.getCikuKeywordsInfoDtoList().size() < 1){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请增加关键词");
        }

        CikuKeywordsReply cikuKeywordsReply = new CikuKeywordsReply();
        BeanUtils.copyProperties(cikuKeywordsReplyInfoDto, cikuKeywordsReply);
        if(cikuKeywordsReplyInfoDto.getType() == 0){ //常规回复
            cikuKeywordsReply.setContent(cikuKeywordsReplyInfoDto.getReply());
        }else if(cikuKeywordsReply.getType() == 1){  //卡片回复
            Map<String,String> card = new HashMap<>();
            card.put("cardtitle",cikuKeywordsReplyInfoDto.getCardtitle());
            card.put("carddesc",cikuKeywordsReplyInfoDto.getCarddesc());
            card.put("cardurl",cikuKeywordsReplyInfoDto.getCardurl());
            card.put("cardicon",cikuKeywordsReplyInfoDto.getCardicon());
            cikuKeywordsReply.setContent(Tools.getStrEmpty(JSONObject.toJSONString(card)));
        }else if(cikuKeywordsReply.getType() == 2){ //小程序回复
            Map<String,String> miniPro = new HashMap<>();
            miniPro.put("miniProTitle",cikuKeywordsReplyInfoDto.getMiniProTitle());
            miniPro.put("miniProDesc",cikuKeywordsReplyInfoDto.getMiniProDesc());
            miniPro.put("miniProName",cikuKeywordsReplyInfoDto.getMiniProName());
            miniPro.put("miniProUrl",cikuKeywordsReplyInfoDto.getMiniProUrl());
            miniPro.put("miniImgPwdStr",cikuKeywordsReplyInfoDto.getMiniImgPwdStr());
            miniPro.put("miniImgStr",cikuKeywordsReplyInfoDto.getMiniImgStr());
            miniPro.put("miniProAppId",cikuKeywordsReplyInfoDto.getMiniProAppId());
            miniPro.put("miniProGhId",cikuKeywordsReplyInfoDto.getMiniProGhId());
            cikuKeywordsReply.setContent(Tools.getStrEmpty(JSONObject.toJSONString(miniPro)));
        }else if(cikuKeywordsReply.getType() == 3){ //添加微信好友名片回复
            if(StringUtils.isBlank(cikuKeywordsReplyInfoDto.getWxid())){
                throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请增加微信id");
            }
            cikuKeywordsReply.setContent(cikuKeywordsReplyInfoDto.getWxid());
        }

        Integer now = DateUtil.getNowTime();
        Long replyId = IdWorker.getId();
        cikuKeywordsReply.setId(replyId);
        cikuKeywordsReply.setCreateTime(now);
        cikuKeywordsReply.setUpdateTime(now);
        cikuKeywordsReply.setStatus(1); //默认启用
        cikuKeywordsReplyMapper.insert(cikuKeywordsReply);

        //关键词list
        for (CikuKeywordsInfoDto cikuKeywordsInfoDto : cikuKeywordsReplyInfoDto.getCikuKeywordsInfoDtoList()){

            cikuKeywordsInfoDto.setMerId(cikuKeywordsReplyInfoDto.getMerId());

            if(cikuKeywordsInfoDto.getType() == null){
                throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "触发类型不能为空");
            }
            if(StringUtils.isBlank(cikuKeywordsInfoDto.getKeyword())){
                throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.CIKUKEY_NULL);
            }
            CikuKeywords nowKey = cikuKeywordsMapper.getByKeywordAndDeviceUniqueId(cikuKeywordsInfoDto.getKeyword(), cikuKeywordsReplyInfoDto.getMerId(), cikuKeywordsInfoDto.getDeviceUniqueId());
            if (nowKey != null){
                throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION,String.format(ResponseMsg.CIKUKEY_EXIST, cikuKeywordsInfoDto.getKeyword()));
            }
            CikuKeywords ck_new = new CikuKeywords();
            ck_new.setId(IdWorker.getId());
            ck_new.setMerId(cikuKeywordsReplyInfoDto.getMerId());
            ck_new.setReplyId(replyId);
            ck_new.setDeviceUniqueId(cikuKeywordsInfoDto.getDeviceUniqueId());
            ck_new.setKeyword(cikuKeywordsInfoDto.getKeyword());
            ck_new.setType(cikuKeywordsInfoDto.getType());
            ck_new.setCreateTime(now);
            ck_new.setUpdateTime(now);
            cikuKeywordsMapper.insertSelective(ck_new);
        }

    }

    /**
     * 修改超级问答回复语
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param cikuKeywordsReplyInfoDto
     * @return null
     */
    @Transactional
    public void updateCikuKeywordsReply(CikuKeywordsReplyInfoDto cikuKeywordsReplyInfoDto){

        if(cikuKeywordsReplyInfoDto.getId() == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id不能为空");
        }

        if(cikuKeywordsReplyInfoDto.getType() == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入回复语类型");
        }

        if(cikuKeywordsReplyInfoDto.getCikuKeywordsInfoDtoList() == null || cikuKeywordsReplyInfoDto.getCikuKeywordsInfoDtoList().size() < 1){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请增加关键词");
        }

        CikuKeywordsReply cikuKeywordsReply = cikuKeywordsReplyMapper.selectById(cikuKeywordsReplyInfoDto.getId(), cikuKeywordsReplyInfoDto.getMerId());

        if(cikuKeywordsReply == null ){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该回复语不存在");
        }

        if(cikuKeywordsReplyInfoDto.getType() == 0){ //常规回复
            cikuKeywordsReply.setContent(cikuKeywordsReplyInfoDto.getReply());
        }else if(cikuKeywordsReply.getType() == 1){  //卡片回复
            Map<String,String> card = new HashMap<>();
            card.put("cardtitle",cikuKeywordsReplyInfoDto.getCardtitle());
            card.put("carddesc",cikuKeywordsReplyInfoDto.getCarddesc());
            card.put("cardurl",cikuKeywordsReplyInfoDto.getCardurl());
            card.put("cardicon",cikuKeywordsReplyInfoDto.getCardicon());
            cikuKeywordsReply.setContent(Tools.getStrEmpty(JSONObject.toJSONString(card)));
        }else if(cikuKeywordsReply.getType() == 2){ //小程序回复
            Map<String,String> miniPro = new HashMap<>();
            miniPro.put("miniProTitle",cikuKeywordsReplyInfoDto.getMiniProTitle());
            miniPro.put("miniProDesc",cikuKeywordsReplyInfoDto.getMiniProDesc());
            miniPro.put("miniProName",cikuKeywordsReplyInfoDto.getMiniProName());
            miniPro.put("miniProUrl",cikuKeywordsReplyInfoDto.getMiniProUrl());
            miniPro.put("miniImgPwdStr",cikuKeywordsReplyInfoDto.getMiniImgPwdStr());
            miniPro.put("miniImgStr",cikuKeywordsReplyInfoDto.getMiniImgStr());
            miniPro.put("miniProAppId",cikuKeywordsReplyInfoDto.getMiniProAppId());
            miniPro.put("miniProGhId",cikuKeywordsReplyInfoDto.getMiniProGhId());
            cikuKeywordsReply.setContent(Tools.getStrEmpty(JSONObject.toJSONString(miniPro)));
        }else if(cikuKeywordsReply.getType() == 3){ //添加微信好友名片回复
            if(StringUtils.isBlank(cikuKeywordsReplyInfoDto.getWxid())){
                throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请增加微信id");
            }
            cikuKeywordsReply.setContent(cikuKeywordsReplyInfoDto.getWxid());
        }

        Integer now = DateUtil.getNowTime();
        cikuKeywordsReply.setUpdateTime(now);
        cikuKeywordsReplyMapper.updateById(cikuKeywordsReply);

        // 删除关键字
        cikuKeywordsMapper.delByReplyId(cikuKeywordsReplyInfoDto.getId(), cikuKeywordsReplyInfoDto.getMerId());

        //关键词list
        for (CikuKeywordsInfoDto cikuKeywordsInfoDto : cikuKeywordsReplyInfoDto.getCikuKeywordsInfoDtoList()){

            cikuKeywordsInfoDto.setMerId(cikuKeywordsReplyInfoDto.getMerId());

            if(cikuKeywordsInfoDto.getType() == null){
                throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "触发类型不能为空");
            }
            if(StringUtils.isBlank(cikuKeywordsInfoDto.getKeyword())){
                throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.CIKUKEY_NULL);
            }
            CikuKeywords nowKey = cikuKeywordsMapper.getByKeywordAndDeviceUniqueId(cikuKeywordsInfoDto.getKeyword(), cikuKeywordsReplyInfoDto.getMerId(), cikuKeywordsInfoDto.getDeviceUniqueId());
            if (nowKey != null){
                throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION,String.format(ResponseMsg.CIKUKEY_EXIST,cikuKeywordsInfoDto.getKeyword()));
            }
            CikuKeywords ck_new = new CikuKeywords();
            ck_new.setId(IdWorker.getId());
            ck_new.setMerId(cikuKeywordsReplyInfoDto.getMerId());
            ck_new.setReplyId(cikuKeywordsReplyInfoDto.getId());
            ck_new.setDeviceUniqueId(cikuKeywordsInfoDto.getDeviceUniqueId());
            ck_new.setKeyword(cikuKeywordsInfoDto.getKeyword());
            ck_new.setType(cikuKeywordsInfoDto.getType());
            ck_new.setCreateTime(now);
            ck_new.setUpdateTime(now);
            cikuKeywordsMapper.insertSelective(ck_new);
        }
    }

    /**
     * 删除
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param cikuKeywordsReplyIdListDto
     * @return null
     */
    @Transactional
    public void deleteCikuKeywordsReply(CikuKeywordsReplyIdListDto cikuKeywordsReplyIdListDto){

        List<Long> idList = cikuKeywordsReplyIdListDto.getIdList();

        if(idList == null || idList.size() == 0){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id不能为空");
        }
        for (Long id : idList){
            // 删除关键字
            cikuKeywordsMapper.delByReplyId(id, cikuKeywordsReplyIdListDto.getMerId());
            cikuKeywordsReplyMapper.deleteById(id, cikuKeywordsReplyIdListDto.getMerId());
        }
    }

    /**
     * 查询超级问答回复语
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param cikuKeywordsReplyIdDto
     * @return null
     */
    public CikuKeywordsReplyInfoVo findCikuKeywordsReplyInfo(CikuKeywordsReplyIdDto cikuKeywordsReplyIdDto){
        if(cikuKeywordsReplyIdDto.getId() == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id不能为空");
        }

        CikuKeywordsReply cikuKeywordsReply = cikuKeywordsReplyMapper.selectById(cikuKeywordsReplyIdDto.getId(), cikuKeywordsReplyIdDto.getMerId());

        if(cikuKeywordsReply == null ){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该回复语不存在");
        }

        CikuKeywordsReplyInfoVo cikuKeywordsReplyInfoVo = new CikuKeywordsReplyInfoVo();
        BeanUtils.copyProperties(cikuKeywordsReply,cikuKeywordsReplyInfoVo);


        String content  = cikuKeywordsReply.getContent();
        if(cikuKeywordsReply.getType() == 0){//常规回复
            cikuKeywordsReplyInfoVo.setReply(cikuKeywordsReply.getContent());
        }else if(cikuKeywordsReply.getType() == 1){//卡片回复
            JSONObject contentObject = JSONObject.parseObject(content);
            cikuKeywordsReplyInfoVo.setCardtitle(contentObject.getString("cardtitle"));
            cikuKeywordsReplyInfoVo.setCardurl(contentObject.getString("cardurl"));
            cikuKeywordsReplyInfoVo.setCardicon(contentObject.getString("cardicon"));
            cikuKeywordsReplyInfoVo.setCarddesc(contentObject.getString("carddesc"));
        }else if(cikuKeywordsReply.getType() == 2){//小程序回复
            JSONObject contentObject = JSONObject.parseObject(content);
            cikuKeywordsReplyInfoVo.setMiniProName(contentObject.getString("miniProName"));
            cikuKeywordsReplyInfoVo.setMiniProTitle(contentObject.getString("miniProTitle"));
            cikuKeywordsReplyInfoVo.setMiniProUrl(contentObject.getString("miniProUrl"));
            cikuKeywordsReplyInfoVo.setMiniProDesc(contentObject.getString("miniProDesc"));
            cikuKeywordsReplyInfoVo.setMiniImgPwdStr(contentObject.getString("miniImgPwdStr"));
            cikuKeywordsReplyInfoVo.setMiniImgStr(contentObject.getString("miniImgStr"));
            cikuKeywordsReplyInfoVo.setMiniProAppId(contentObject.getString("miniProAppId"));
            cikuKeywordsReplyInfoVo.setMiniProGhId(contentObject.getString("miniProGhId"));
        }else if(cikuKeywordsReply.getType() == 3){//微信好友名片
            cikuKeywordsReplyInfoVo.setWxid(cikuKeywordsReply.getContent());
        }

        //关键字对象列表
        CikuKeywordsQuery cikuKeywordsQuery = new CikuKeywordsQuery();
        cikuKeywordsQuery.setMerId(cikuKeywordsReply.getMerId());
        cikuKeywordsQuery.setReplyId(cikuKeywordsReply.getId());
        List<CikuKeywords> cikuKeywordsList = cikuKeywordsMapper.findByList(cikuKeywordsQuery);
        if(cikuKeywordsList != null && cikuKeywordsList.size() > 0){
            List<CikuKeywordsInfoVo> cikuKeywordsInfoVoList = new ArrayList<>();
            List<String> keywordList = new ArrayList<>();
            for (CikuKeywords cikuKeywords : cikuKeywordsList){
                CikuKeywordsInfoVo cikuKeywordsInfoVo = new CikuKeywordsInfoVo();
                BeanUtils.copyProperties(cikuKeywords, cikuKeywordsInfoVo);
                cikuKeywordsInfoVoList.add(cikuKeywordsInfoVo);
                keywordList.add(cikuKeywords.getKeyword());
            }
            cikuKeywordsReplyInfoVo.setCikuKeywordsInfoDtoList(cikuKeywordsInfoVoList);
            cikuKeywordsReplyInfoVo.setKeywordList(keywordList);
        }
        return cikuKeywordsReplyInfoVo;
    }

}
